var express = require('express');
var router = express.Router();
var connection = require('../db/sql.js')
router.all("*", function(req, res, next) {
	res.header("Access-Control-Allow-Origin", "*");
	res.header("Access-Control-Allow-Headers", "X-Requested-With");
	res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OP0TIONS");
	res.header("X-Powered-By", "Express");
	res.header("Content-Type", "text/html; charset=UTF-8");
	next();
});

router.get('/getDoctor', function(req, res, next) { //获取所有医生
	connection.query('select *from doctor', (err, result) => {
		if (err) throw err;
		res.json({
			code: 200,
			result,
		})
	})
})

router.get('/getDoctorInfo', function(req, res, next) {//获取当前医生的信息
	console.log(req.query.docId);
	let docId = req.query.docId
	connection.query(`select *from doctor where docId = "${docId}"`, (err, result) => {
		if (err) throw err;
		res.json({
			code: 200,
			result,
		})
	})
})
router.get('/getMyPatien', function(req, res, next) { //获取登陆医生的id的对应患者
	let docId = req.query.docId
	connection.query(`select *from registrationform where affiliatedDoctorId = "${docId}"`, (err, result) => {
		if (err)  throw err;	
			res.json({
				code: 200,
				result,
			})
	})
})
module.exports = router;